package araujoCoronelVillamayor.plantasVsZombies.uiWicket;

import araujoCoronelVillamayor.plantasVsZombies.appModelsArena.JardinZenAppModel
import araujoCoronelVillamayor.plantasVsZombies.uiWicket.layouts.LayoutPrincipal
import org.apache.wicket.markup.html.basic.Label
import org.apache.wicket.model.CompoundPropertyModel
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods
import org.uqbar.wicket.xtend.XLink
import org.uqbar.wicket.xtend.XListView

class JardinZenPage extends LayoutPrincipal {
	extension WicketExtensionFactoryMethods = new WicketExtensionFactoryMethods
	
	private final JardinPage mainPage
	
	new(JardinZenAppModel JardinZenAppModelParametro, JardinPage mainPage) {
		super();
		
		this.mainPage = mainPage
		defaultModel = new CompoundPropertyModel(JardinZenAppModelParametro)
		
		//Default tipo de plantas que muestra
		this.mostrarJardinZen('Terrestre')
		
		//defaultModel.setPlantaSeleccionadaJardinZen()
		//this.addChild(new Label("tipoPlantaSeleccionada"))
		
        this.addChild(new Label("cantidadPlantasTerrestres"))
        this.addChild(new Label("cantidadPlantasAcuaticas"))
        
        this.addChild(new XLink("botonJardinTerrestre") => [
			onClick = [| 
				mostrarJardinZen("Terrestre")
			]
        ])
        
        this.addChild(new XLink("botonJardinAcuatico") => [
			onClick = [| 
				mostrarJardinZen("Acuatica")
			]
        ])
        this.addChild(new XLink("volverJardin") => [
			onClick = [| volver() ]
        ])

		//-------------------------------------------------------------------------------------//
		//------------------------------- GRILLA JARDIN ZEN -----------------------------------//
		//-------------------------------------------------------------------------------------//
		val listViewZen = new XListView("resultadosJardinZen") //resultados es el id de la tr
//		listViewZen.model = jardinZenAppModel.resultadosJardinZen.asCompoundModel
		listViewZen.populateItem = [ item |
			item.model = item.modelObject.asCompoundModel
			item.addChild(new Label("nombre"))
			item.addChild(new Label("ataque"))
			item.addChild(new Label("defensa"))
			
		]
		this.addChild(listViewZen);
		//-------------------------------------------------------------------------------------//
		//------------------------------- GRILLA JARDIN ZEN -----------------------------------//
		//-------------------------------------------------------------------------------------//
    }
    
	def volver() {
		responsePage = mainPage
	}
	
	def mostrarJardinZen(String tipoTerrenoParam) {
		jardinZenAppModel.refreshJardinZen(tipoTerrenoParam)
	}
    
 	def getJardinZenAppModel() {
		this.defaultModelObject as JardinZenAppModel
	}
}
